package com.kupurui.asteacher.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.webkit.WebView;

/**
 * Created by Administrator on 2017/8/17.
 */

public class MyClickWebView extends WebView {


    public onWebClickListener listener;
    public MyClickWebView(Context context) {
        super(context);
    }

    public MyClickWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyClickWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private float touchX,touchY;

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                touchX = event.getX();
                touchY = event.getY();
                break;
            case MotionEvent.ACTION_UP:
                float x = event.getX();
                float y =event.getY();
                if (Math.abs(touchX-x)<20&&Math.abs(touchY-y)<20)
                    if (listener!=null){
                        listener.onClick(this);
                    }
                break;
        }

        return true;
    }


    public onWebClickListener getListener() {
        return listener;
    }

    public void setListener(onWebClickListener listener) {
        this.listener = listener;
    }

    public interface onWebClickListener{
        void onClick(MyClickWebView webView);
    }

}
